Skip to content

entrypoint: report function errors in the engine's file - #47

Open
vito wants to merge 2 commits into
mainfrom
function-error-file
Open

vito wants to merge 2 commits into
mainfrom
function-error-file

Conversation

@vito

@vito vito commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Depends on dagger/dagger#15249, the engine side: the function error file (DAGGER_FUNCTION_ERROR_PATH) and the build <module> span around an entrypoint's prebuild. On engines without them, nothing changes: the dispatcher falls back to the ::dagger-function-error:: marker, and prebuild is only a member they may build ahead of a call.

This is the Java counterpart of dagger/go-sdk#113 and dagger/python-sdk#93. It is pinned by the Java goldens in dagql/idtui (TestTelemetry/TestGolden/sdks-java-*), which all pass against it.

The error file. When the engine sets DAGGER_FUNCTION_ERROR_PATH, ModuleDispatcher.engineCall writes the function's error there as {"message": ..., "values": {...}}:

  • message is the error's full message, with the [traceparent:…] origins it names, so the engine finds the call that failed;
  • values are the extensions of the GraphQL error the exception is or wraps (its cause chain), verbatim, such as an ExecError's exitCode, stdout, stderr and cmd;
  • a report over the 1 MiB the engine reads is shortened as go-sdk does: long strings keep their end, the message its start and its origins, then the values go.

It then prints no marker and no full stack trace. If the variable is unset or the file can't be written, the old behaviour (full stack trace, then the marker) stays.

Stack traces. With the file:

  • an API error (DaggerQueryException) whose message names an origin prints nothing: the engine shows the failed call with its own logs;
  • any other error, the module's own exceptions and an API error without an origin, prints a short stack trace: the module's own frames only (the JDK, the SDK, the generated entrypoint and clients and the SDK's libraries are left out), causes included, without the origins.

The generated entrypoint.

  • raiseFunctionError raises the exec error as it is when it carries functionError, the report the engine read.
  • It declares prebuild(platform: Platform): File!, the jar every call runs, so the engine builds it ahead of the call under a build <module> span. The call builds the same recipe, so it hits the cache.

The build (entrypoint/build.dang.tmpl). Maven now runs in an exec of its own, mvn package [-Ddagger.proc=full] -DskipTests --quiet --threads 1C --no-transfer-progress, instead of inside one sh -c script with the staleness comparison. The comparison runs in its own exec after it. So a broken module's build shows as:

✘ viztestJava: ViztestJava! X.Xs ERROR
┇ build viztest-java ›
✘ withExec mvn package -Ddagger.proc=full -DskipTests --quiet --threads 1C --no-transfer-progress X.Xs ERROR
[ERROR] COMPILATION ERROR :
[ERROR] /src/…/ViztestJava.java:[97,1] class, interface, enum, or record expected
[ERROR] Failed to execute goal … Compilation failure
…
! exit code: 1

where it used to show the script's withExec sh -c 'set -e…' with exit code: 1 and none of the compiler's output. --quiet keeps a successful build silent and a failed one to Maven's errors.

Tests: ModuleDispatcherTest covers the report, the values, the short traces, the fallback and the shortening; DangEntrypointRendererTest covers prebuild and the functionError gate. dagger check packager:unit-tests passes. The e2e errorCheck now asserts the function's own text only, since an engine with the error file drops the call module entrypoint: prefix; a blank exception message is reported as the exception's type, as the engine takes an empty report message for plain text. The e2e checks couldn't run in my sandbox (they need a published engine image of the CLI's version).

When the engine names DAGGER_FUNCTION_ERROR_PATH, the dispatcher writes the
function's error there as {"message", "values"}: the full message, origins
kept, and the extensions of the GraphQL error it is or wraps, verbatim. The
engine fails the call with that error and shows it, so the dispatcher prints
no marker and no full stack trace: an API error whose origin the engine
shows prints nothing, and any other error a short stack trace of the
module's own frames, without origins. Without the variable, or when the file
can't be written, the marker stays as the fallback for older engines.

The generated entrypoint raises the exec error as it is when it carries the
report the engine read (functionError), and declares prebuild, the jar every
call runs, so the engine builds it under a "build <module>" span.

The jar's build runs Maven quietly in an exec of its own, so a failed build
shows the compiler's errors under "mvn package", not a shell script's
"exit code: 1".

Signed-off-by: Alex Suraci <alex@dagger.io>
vito added a commit to dagger/dagger that referenced this pull request Nov 22, 2026
Pin java-sdk to dagger/java-sdk#47 (344e6cf) and regenerate the Java
fixture. Its dispatcher writes a function's error to the engine's
DAGGER_FUNCTION_ERROR_PATH, its entrypoint raises the exec error that
carries it as it is, and it declares prebuild, so its build runs under the
"build viztest-java" span. The clients/sdk-dep client is kept as it was:
generation from this checkout re-targets it at a git ref of this branch.

Goldens:
- fail-native: a short stack trace, the exception and the user's one frame,
  as Python shows one.
- fail-exec-wrapped (today's output, not a target): the cause chain, each
  part through the user's frame only, and no marker, traceparents or
  "call module entrypoint" row.
- broken-default: the build fails in its own "mvn package" exec, which
  shows Maven's quiet errors, the compiler's among them, in place of the
  "[label TBD]" placeholder. The compiler's line is [97,1].

Every sdks-java golden passes.

Signed-off-by: Alex Suraci <alex@dagger.io>
The engine reads a function error report whose message is empty as plain
text, so a blank message is reported as the error's type, as a missing one
is.

The e2e error check asserts the function's own text only: an engine that
gives the dispatcher an error file reports it without the "call module
entrypoint: " prefix older engines add. The dispatcher tests ignore what
OpenTelemetry logs on stderr when an earlier test shut its SDK down.

Signed-off-by: Alex Suraci <alex@dagger.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant